/*
		A count down module for the desktop2 system, displaying uptime and cpu
		
		Author: 	Matthew Allpress
		Created:	12/07/06
		Edited:		24/09/06

*/
var CountDownInfoBackend = "http://localhost:5050/todo/index.php?mid=6";
var cdown_mod_name = "Count Down";

var toAdd = "";
toAdd+= "<div style=\"position: absolute; width: 300px; height: 40px; z-index: 1; left: 300px; top: 0px; background-color: #C0C0C0\" id=\"count_down\">";
toAdd+= "</div>";
document.body.innerHTML+=toAdd;
toAdd = null;

var temp_element = document.getElementById("count_down");

if(module_config[cdown_mod_name]['left'] != "N")
{
	temp_element.style.left = module_config[cdown_mod_name]['left'];
}
else
{
	temp_element.style.right = module_config[cdown_mod_name]['right'];
}

temp_element.style.top = module_config[cdown_mod_name]['top'];
temp_element.style.backgroundColor = module_config[cdown_mod_name]['fc'];

if(module_config[cdown_mod_name]['date'] != "N" && module_config[cdown_mod_name]['event'] != "N")
{	
	window.setInterval("update_count_down('" + module_config[cdown_mod_name]['date'] + "','" + module_config[cdown_mod_name]['event'] + "');", 1000);
}

function update_count_down(date, title)
{
	document.getElementById("count_down").innerHTML = "<p align=\"center\">"+calc_dateDiff(date)+"<br>Till: " + title + "</p>";
}

function calc_dateDiff(time)
{
	var weeks = 0;
	var days = 0;
	var hours = 0;
	var minutes = 0;
	var date_now = Date.parse(Date());
	var date_then = Date.parse(time);
	time = date_then - date_now;
	
	time = Math.floor(time / 1000);
	weeks = Math.floor(time / 604800);
	time = Math.floor(time % 604800);
	days = Math.floor(time / 86400);
	time = Math.floor(time % 86400);
	hours = Math.floor(time / 3600);
	time = Math.floor(time % 3600);
	minutes = Math.floor(time / 60);
	time = Math.floor(time % 60);
	toReturn = weeks + "w " + days + "d " + hours + "h " + minutes + "m " + time + "s";
	time = null;
	days = null;
	hours = null;
	minutes = null;
	return(toReturn);
}